Skip to content

Upsert testing plan #4470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
14 of 74 tasks
dminor opened this issue May 6, 2025 · 8 comments
Open
14 of 74 tasks

Upsert testing plan #4470

dminor opened this issue May 6, 2025 · 8 comments

Comments

@dminor
Copy link
Contributor

dminor commented May 6, 2025

Proposal: https://github.com/tc39/proposal-upsert
Rendered specification text: https://tc39.es/proposal-upsert/
Implementations: engine262, SpiderMonkey

Map.getOrInsert

  • Appending a new value normalizes -0 and +0
  • Appending new values
  • Appending new values with missing key
  • Throw a type error if this is a Set
  • Throw a type error if this is a WeakMap
  • Throw a type error if this is does not have a [[MapData]] slot
  • Verify properties of getOrInsert
  • Verify length of getOrInsert
  • Verify name of getOrInsert
  • Verify getOrInsert is not a constructor
  • Check return value when key is not present
  • Check return value when key is present
  • Check return value for normalized key
  • Throw a type error if this is not an Object

Map.getOrInsertComputed

  • Appending a new value normalizes -0 and +0
  • Appending new values
  • Appending new values with missing key
  • Check abrupt completion from callback function
  • Verify behaviour for callable callback function
  • Verify that callback function is not called if key is present
  • Verify that this is undefined and the callback receives exactly one argument
  • Throw a type error if this is a Set
  • Throw a type error if this is a WeakMap
  • Throw a type error if this is does not have a [[MapData]] slot
  • Verify properties of getOrInsertComputed
  • Verify length of getOrInsertComputed
  • Verify name of getOrInsertComputed
  • Verify getOrInsertComputed is not a constructor
  • Verify that a TypeError is thrown if callback function is not callable
  • Verify that a TypeError is thrown if callback function is not callable even when key is present
  • Verify that mutation of value corresponding to the key during callback function execution is overwritten
  • Verify state of the Map after getOrInsertComputed if the callback throws
  • Verify state of the Map after getOrInsertComputed if the callback mutates the Map and then throws
  • Map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted
  • Check return value when key is not present
  • Check return value when key is present
  • Check return value for normalized key
  • Throw a type error if this is not an Object

WeakMap.getOrInsert

  • Add object key if key is not present in the map
  • Add symbol key if key is not present in the map
  • Throw TypeError if this does not have a [[WeakMapData]] slot
  • Verify properties of getOrInsert
  • Verify length of getOrInsert
  • Verify name of getOrInsert
  • Verify getOrInsert is not a constructor
  • Check return value when object key is not present
  • Check return value when symbol key is not present
  • Check return value when object key is present
  • Check return value when symbol key is present
  • Throw a type error if this is not an Object
  • Throw a type error if key is not weakly holdable

WeakMap.getOrInsertComputed

  • Add object key if key is not present in the map
  • Add symbol key if key is not present in the map
  • Appending new values with missing key
  • Check abrupt completion from callback function
  • Verify that callback function is not called if key is present
  • Verify that this is undefined and the callback receives exactly one argument
  • Throw TypeError if this does not have a [[WeakMapData]] slot
  • Verify properties of getOrInsertComputed
  • Verify length of getOrInsertComputed
  • Verify name of getOrInsertComputed
  • Verify getOrInsertComputed is not a constructor
  • Verify that a TypeError is thrown if callback function is not callable
  • Verify that a TypeError is thrown if callback function is not callable even when key is present
  • Verify that mutation of value corresponding to the key during callback function execution is overwritten
  • Verify state of the WeakMap after getOrInsertComputed if the callback throws
  • Verify state of the WeakMap after getOrInsertComputed if the callback mutates the WeakMap and then throws
  • Map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted
  • Check return value when object key is not present
  • Check return value when symbol key is not present
  • Check return value when object key is present
  • Check return value when symbol key is present
  • Throw a type error if this is not an Object
  • Throw a type error if key is not weakly holdable
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented May 6, 2025

For the callback cases, maybe also check that this is undefined and that it receives exactly one argument (since in other built-in callbacks the object that the callback-taking method is called on would be passed as this).

Verify that a TypeError is thrown if callback function is not callable

This needs to check that is also throws if the key is already present (thus it does not try to call the callback).


(sorry I didn't read the tests, these are just drive-by comments about this list)

@michaelficarra
Copy link
Member

In getOrInsertComputed, check the state of the map after catching an exception thrown by the callback (both after mutating and non-mutating).

@dminor
Copy link
Contributor Author

dminor commented May 7, 2025

In getOrInsertComputed, check the state of the map after catching an exception thrown by the callback (both after mutating and non-mutating).

Checking the state would mean to check that the keys and values are what we expect, with what we expect depending on whether the callback mutates the map or not?

@michaelficarra
Copy link
Member

yep

@ptomato
Copy link
Contributor

ptomato commented May 8, 2025

Thanks for putting this together! I'd suggest one more case for getOrInsertComputed: the map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted.

@dminor
Copy link
Contributor Author

dminor commented May 13, 2025

Map.prototype.getOrInsert tests were merged in #4472

@dminor
Copy link
Contributor Author

dminor commented May 15, 2025

Thanks for putting this together! I'd suggest one more case for getOrInsertComputed: the map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted.

Turns out there was already coverage for this case in overwrites-mutation-from-callback.js.

@michaelficarra
Copy link
Member

Map.prototype.getOrInsertComputed tests: #4491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants